<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Cart;
class cartController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $goods = [
            1=>['id'=>1,'name'=>'商品1','price'=>13,'des'=>'啊啊啊啊啊'],
            2=>['id'=>2,'name'=>'商品2','price'=>56,'des'=>'额鹅鹅鹅'],
            3=>['id'=>3,'name'=>'商品3','price'=>87989,'des'=>'哈哈哈哈哈'],
            4=>['id'=>4,'name'=>'商品4','price'=>819,'des'=>'哈哈哈哈哈'],
            5=>['id'=>5,'name'=>'商品4','price'=>8899,'des'=>'哈哈哈哈哈'],
        ];
       return view('carts.goods',[
            'goods'=>$goods,
        ]);
    }
    public function addcart($id)
    {
        $goods=[
            1=>['id'=>1,'name'=>'商品1','price'=>13,'des'=>'啊啊啊啊啊'],
            2=>['id'=>2,'name'=>'商品2','price'=>56,'des'=>'额鹅鹅鹅'],
            3=>['id'=>3,'name'=>'商品3','price'=>87989,'des'=>'哈哈哈哈哈'],
            4=>['id'=>4,'name'=>'商品4','price'=>819,'des'=>'哈哈哈哈哈'],
            5=>['id'=>5,'name'=>'商品4','price'=>8899,'des'=>'哈哈哈哈哈'],
        ];
       $product = $goods[$id];
       //id  name  qty  price opt
       Cart::add($product['id'],$product['name'],1,$product['price']);
       return redirect('/cart/info');
    }
   public function cartinfo()
   {
        $carts = Cart::content();
        //总额 不含税
        $total = Cart::subtotal();
        //购物车商品数量
        $count = Cart::count();
        /**
         * 显示购车的详情页
         */
        return view('carts.cart',[
            'cart'=>$carts,
            'total'=>$total,
            'count'=>$count,
            ]);
   }
   /**
    * 删除购物车的商品
    */
   public function del($rowid)
   {
        Cart::remove($rowid);
        return redirect('/cart/info');
   }
   /**
    * 清空购物车
    */
   public function destroy()
   {
        Cart::destroy();
        return redirect('/cart/info');
   }

}
